<?php
/**
 * @file /Db/Statement/mysql.php
 *
 * Statement representation of MySQL-Querys.
 *
 * @copydoc Db_Statement
 *
 * http://code.google.com/p/rpd/wiki/mysql.php
 *
 * New BSD License
 * \n
 * Copyright (c) 2010 Rpd-Team
 *
 * @namespace  rpd
 * @since      0.1.0
 * @version    0.1.0
 */

/**
 *
 */

class Db_Statement_mysql extends Db_Statement implements Db_Statement_Interface {

	public function rowCount()
	{
		return mysql_num_rows($this->_result);
	}

	public function current ()
	{
		return $this->_current;
	}

	public function next ()
	{
		$this->_line++;
		$this->_current = mysql_fetch_assoc($this->_result);
	}

	public function key ()
	{
		return $this->_line;
	}

	public function valid ()
	{
		return ($this->_valid != 0 && $this->_line <= $this->_valid);
	}

	public function rewind ()
	{
		if ($this->_valid == 0)
		{
				$this->_current = false;
		}
		else if ($this->_line != 1)
		{
			mysql_data_seek($this->_result, 0);		// goto first line
			$this->_line = 1;						// reset counter
			$this->_current = mysql_fetch_assoc($this->_result);
		}
	}

	function __construct($result, $statement = "unknown") {
		if ($result === false)
		{
			echo mysql_error();
		}

		$this->_valid = mysql_num_rows($result);
		parent::__construct($result, $statement);
	}
}

?>